<!--个人中心-->
<template>
  <el-container>
    <el-header>
      <h1>个人中心</h1>
    </el-header>
    <el-main>
      <el-button type="primary" @click="ChangePwd">修改密码</el-button>
      <el-button type="danger" @click="deluser">注销用户</el-button>
      <h1>用户信息</h1>
      <el-table :data="tableData">
        <el-table-column label="邮箱地址" prop="mail"/>
        <el-table-column label="用户名" prop="username"/>
        <el-table-column label="性别" width="100px">
          <template #default="data">
            <span>{{ data.row.sex == 0 ? '男' : '女' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="身份证号" prop="idcard"/>
        <el-table-column label="所属班级" prop="grade"/>
        <el-table-column label="权限等级">
          <template #default="data">
            <span>{{ LevelJudge(data.row.level) }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </el-container>
</template>

<script>
import {request} from "@/network/request";
import {LevelJudge} from "@/components/function/LevelJudge";
import {DateJudge} from "@/components/function/DateJudge";
import {delectmail} from "@/components/request/delectmail";
import {ElMessageBox} from "element-plus";

export default {
  name: "UserDate",
  data() {
    return {
      tableData: null
    }
  },
  mounted() {
    this.demo();
  },
  methods: {
    LevelJudge,
    demo() {
      request({
        url: '/login/showmail',
        params: {
          mail: this.$store.state.mail
        }
      }).then(res => {
        if (res.data.success) {
          this.$data.tableData = res.data.data
        } else {
          this.$message({
            type: 'warning',
            message: '数据错误' + res.data.message
          });
        }
      }).catch(err => {
        this.$message({
          type: 'warning',
          message: '数据错误' + err
        });
      })
    },
    //修改密码
    ChangePwd() {
      this.$router.push('/EmailCheck');
    },
    // 注销用户
    deluser() {
      this.$prompt('请输入:"确定要注销账户"', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({value}) => {
        if (value == "确定要注销账户") {
          delectmail(this.$store.state.mail);
          ElMessageBox.alert('删除成功', 'Title', {
            confirmButtonText: 'OK',
            callback: () => {
              this.$router.push('/');
            }
          })
        } else {
          this.$message({
            type: 'info',
            message: '请正确输入'
          });
        }

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    }
  }
}
</script>

<style scoped>

</style>